<?php
/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/4/17
 * Time: 上午11:34
 */

namespace App\Http\Controllers\Auth;


use App\Http\Controllers\BaseController;
use App\Logic\PartTimeJobLogic;
use Illuminate\Http\Request;
use Validator;

/**
 * 兼职,实习
 *
 * Class PartTimeJobController
 * @package App\Http\Controllers\Auth
 */
class PartTimeJobController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->setToken(false);
    }

    /**
     * 列表
     *
     * @param Request $request
     * @return array
     */
    public function getList(Request $request)
    {
        $rule = [
            'type' => 'required|string',
            'pagesize' => 'required|int',
            'last_id' => 'required|int',
        ];
        $message = [
            'type.required' => '类型不能为空',
            'pagesize.required' => '每页个数不能为空',
            'last_id.required' => '页码不能为空',
        ];
        $validator = Validator::make($request->all(), $rule, $message);
        $errors = $validator->errors()->all();
        if ($errors && !$validator->passes()) {
            return $this->error($errors[0], 206);
        }
        return PartTimeJobLogic::getList($request->all());
    }

    /**
     * 详情
     *
     * @param Request $request
     * @return array
     */
    public function detail(Request $request)
    {
        $params = $request->all();
        $rule = [
            'id' => 'required|int',
        ];
        $message = [
            'id.required' => 'ID不能为空',
        ];
        $validator = Validator::make($params, $rule, $message);
        $errors = $validator->errors()->all();
        if ($errors && !$validator->passes()) {
            return $this->error($errors[0], 206);
        }
        return PartTimeJobLogic::detail($params['id'],$this->userId);
    }

}